package com.intre.open.gwtjpa.data.first.server.dao;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.apache.log4j.Logger;

import com.intre.open.gwtjpa.data.first.domain.Person;


public class DataFirstDAO {

	static final Logger logger = Logger.getLogger(DataFirstDAO.class);
	public final static String NAME = "dataFirstDAO";
	
	@PersistenceContext(unitName="data_first_pu")
	protected EntityManager entityManager;
	
	protected void setEntityManager(EntityManager entityManager) {
		this.entityManager = entityManager;
	}
	
	protected EntityManager getEntityManager() {
		return entityManager;
	}
		
	@SuppressWarnings("unchecked")
	public List<Person> loadAll() {
		Query query = getEntityManager().createQuery("FROM Person");
		return (List<Person>) query.getResultList();
	}
	
}
